<?php
/**
 * 应用配置文件
 */

// 应用配置
$appConfig = [
    'app_name' => '健康营养食谱小程序',
    'version' => '1.0.0',
    'debug' => true,
    'secret_key' => 'your-secret-key-here',
    'token_expire' => 7200, // token过期时间(秒)
    'upload_path' => __DIR__ . '/../uploads/',
    'allowed_image_types' => ['jpg', 'jpeg', 'png', 'gif'],
    'max_upload_size' => 5 * 1024 * 1024 // 5MB
];

// 微信小程序配置
$wechatConfig = [
    'appid' => 'your-wechat-appid',
    'secret' => 'your-wechat-secret',
    'code2session_url' => 'https://api.weixin.qq.com/sns/jscode2session'
];

// API响应格式
function apiResponse($code, $message, $data = null) {
    return [
        'code' => $code,
        'message' => $message,
        'data' => $data,
        'timestamp' => time()
    ];
}

// 成功响应
function apiSuccess($data = null, $message = '操作成功') {
    return apiResponse(200, $message, $data);
}

// 错误响应
function apiError($message = '操作失败', $code = 400) {
    return apiResponse($code, $message);
}

// 验证参数
function validateParams($params, $required) {
    foreach ($required as $field) {
        if (!isset($params[$field]) || empty($params[$field])) {
            throw new Exception("参数 {$field} 不能为空");
        }
    }
    return true;
}

?>